/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package canteen.sys.model.entity.repository;

import canteen.sys.model.entity.DepartmentMaster;
import canteen.sys.model.generic.GenericHibernateDAOSupport;
import java.util.List;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author TNT
 */
public class DepartmentMasterDAOImpl extends GenericHibernateDAOSupport<DepartmentMaster, Long> implements DepartmentMasterDAO {

    @Override
    public List<DepartmentMaster> findAllByStatus(boolean status) {
        Transaction transaction = getSession().beginTransaction();
        List<DepartmentMaster> listDepartment = getSession().createCriteria(DepartmentMaster.class)
                .add(Restrictions.eq("status", status)).list();
        transaction.commit();
        return listDepartment;
    }
    //binh thuong cac method insert, update, delete no da duoc ke thua tu lop khac roi!

    @Override
    public List<DepartmentMaster> findByNameAndStatus(String name, boolean status) {
        Transaction transaction = getSession().beginTransaction();
        List<DepartmentMaster> listDepartment = getSession().createCriteria(DepartmentMaster.class)
                .add(Restrictions.like("departmentName", "%" + name + "%"))
                .add(Restrictions.eq("status", status)).list();
        transaction.commit();
        
        //roi chay di =))
        return listDepartment;
    }
}
